#include "my_service.pb.h"
#include "xlcomm/base/logger.h"
using namespace xlcomm;

class MyServiceImpl : public MyService {
 public:
  void Echo(::google::protobuf::RpcController* controller,
            const ::xlcomm::EchoRequest* request,
            ::xlcomm::EchoResponse* response,
            ::google::protobuf::Closure* done) override {
    LOG_DEBUG << "MyServiceImpl::" << __FUNCTION__
              << "==== request:" << request->msg();
    response->set_msg(request->msg() + ", echo");
    if (done) done->Run();
  }

  void Add(::google::protobuf::RpcController* controller,
           const ::xlcomm::AddReuest* request, ::xlcomm::AddResponse* response,
           ::google::protobuf::Closure* done) override {
    int a = request->a();
    int b = request->b();
    LOG_DEBUG << "MyServiceImpl::" << __FUNCTION__ << "==== a:" << a
              << ", b:" << b;
    response->set_result(a + b);
    if (done) done->Run();
  }

  void QueryPerson(::google::protobuf::RpcController* controller,
                   const ::xlcomm::PersonRequest* request,
                   ::xlcomm::PersonResponse* response,
                   ::google::protobuf::Closure* done) override {
    LOG_DEBUG << "MyServiceImpl::" << __FUNCTION__ << "====";
    response->set_age(request->id());
    response->set_name(request->name() + "xx");
    response->set_age(request->age() + 2);
    if (done) done->Run();
  }
};